<extend name="Base/common" />
<block name="header">
<header class="jumbotron subhead" id="overview">
  <div class="container">
    <h2>用户注册</h2>
    <p><span><span class="pull-left"><span>已经有账号? <a href="{:U('User/login')}">点此登录</a> </span> </span></p>
  </div>
</header>
</block>

<block name="body">

<section>
	<div class="span12">
        <form action="{:U()}" method="post" class="form-horizontal" enctype="multipart/form-data">
          <div class="control-group">
            <label class="control-label" for="inputEmail">用户名</label>
            <div class="controls">
                <input type="text" class="text input-large user" name="user" value=""
                placeholder="请输入用户名">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputPassword">密码</label>
            <div class="controls">
                <input type="password" class="text input-large pwd1" name="pwd1" value="" placeholder="请输入密码">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputPassword">确认密码</label>
            <div class="controls">
                <input type="password" class="text input-large pwd2" name="pwd" value="" placeholder="请再次输入密码，两次密码一致">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputEmail">邮箱</label>
            <div class="controls">
                <input type="text" class="text input-large email" name="email" value=""
                placeholder="请输入电子邮件">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label">电话</label>
            <div class="controls">  
                <input type="text" class="text input-large tall" name="tall" value=""placeholder="请输入电话 ">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" >地址</label>
            <div class="controls">  
                <input type="text" class="text input-large address" name="address" value=""placeholder="请输入住址 ">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" >头像</label>
            <div class="controls">
                <input type="file"  name="file" id="doc" multiple="multiple"  style="width:200px;border-radius:20px" onchange="javascript:setImagePreviews();" accept="image/*" />
                <div id="dd" style=" width:200px;"></div>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputPassword">验证码</label>
            <div class="controls">
              <input type="text" id="inputPassword" class="span3" placeholder="请输入验证码"  errormsg="请填写5位验证码" nullmsg="请填写验证码" datatype="*5-5" name="verify">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label"></label>
            <div class="controls">
                <img class="verifyimg reloadverify" alt="点击切换" src="{:U('verify')}" style="cursor:pointer;">
            </div>
            <div class="controls Validform_checktip text-warning"></div>
          </div>
          <div class="control-group">
            <div class="controls">
              <button type="submit" class="btn">注 册</button>
            </div>
          </div>
        </form>
	</div>
</section>

</block>

<block name="side"> </block>
<block name="script">
	<script type="text/javascript">
    	$(document)
	    	.ajaxStart(function(){
	    		$("button:submit").addClass("log-in").attr("disabled", true);
	    	})
	    	.ajaxStop(function(){
	    		$("button:submit").removeClass("log-in").attr("disabled", false);
	    	});


    	$("form").submit(function(){
    		var self = $(this);
    		$.post(self.attr("action"), self.serialize(), success, "json");
    		return false;

    		function success(data){
    			if(data.status){
    				window.location.href = data.url;
    			} else {
    				self.find(".Validform_checktip").text(data.info);
    				//刷新验证码
    				$(".reloadverify").click();
    			}
    		}
    	});

		$(function(){
			var verifyimg = $(".verifyimg").attr("src");
            $(".reloadverify").click(function(){
                if( verifyimg.indexOf('?')>0){
                    $(".verifyimg").attr("src", verifyimg+'&random='+Math.random());
                }else{
                    $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
                }
            });
		});

    $(function(){
            $(".user").blur(function(){
                var user=$(".user").val();
                $.post("{:U('Suser/ajuser')}",{user:user},
                    function(data){
                      if(data.status==0){
                          $(".user").nextAll().remove();
                          $(".user").after(data.data);
                      }else if(data.status==1){
                          $(".user").nextAll().remove();
                          $(".user").after(data.data);
                      }else if(data.status==2){
                          $(".user").nextAll().remove();
                          $(".user").after(data.data);
                      }
                });
            });
         });

         $(function(){
            $(".email").blur(function(){
                var email=$(".email").val();
                $.post("{:U('Suser/ajemail')}",{email:email},
                    function(data){
                      if(data.status==0){
                          $(".email").nextAll().remove();
                          $(".email").after(data.data);
                      }else if(data.status==1){
                          $(".email").nextAll().remove();
                          $(".email").after(data.data);
                      }else if(data.status==2){
                          $(".email").nextAll().remove();
                          $(".email").after(data.data);
                      } 
                });
            });
         });

         $(function(){
            $(".tall").blur(function(){
                var tall=$(".tall").val();
                $.post("{:U('Suser/ajtall')}",{tall:tall},
                    function(data){
                      if(data.status==0){
                          $(".tall").nextAll().remove();
                          $(".tall").after(data.data);
                      }else if(data.status==1){
                          $(".tall").nextAll().remove();
                          $(".tall").after(data.data);
                      }else if(data.status==2){
                          $(".tall").nextAll().remove();
                          $(".tall").after(data.data);
                      }   
                });
            });
         });

         $(function(){
            $(".address").blur(function(){
                var address=$(".address").val();
                $.post("{:U('Suser/ajaddress')}",{address:address},
                    function(data){
                      if(data.status==0){
                          $(".address").nextAll().remove();
                          $(".address").after(data.data);
                      }else{
                          $(".address").nextAll().remove();
                          $(".address").after(data.data);
                      }  
                });
            });
         });

         $(function(){
            $(".pwd1").blur(function(){
                var pwd1=$(".pwd1").val();
                $.post("{:U('Suser/ajpwd1')}",{pwd1:pwd1},
                    function(data){
                      if(data.status==0){
                          $(".pwd1").nextAll().remove();
                          $(".pwd1").after(data.data);
                      }else{
                          $(".pwd1").nextAll().remove();
                          $(".pwd1").after(data.data);
                      }  
                });
            });
         });

        $(function(){
            $(".pwd2").blur(function(){
                var pwd1=$(".pwd1").val();
                var pwd2=$(".pwd2").val();
                $.post("{:U('Suser/ajpwd')}",{pwd2:pwd2,pwd1:pwd1},
                    function(data){
                      if(data.status==0){
                          $(".pwd2").nextAll().remove();
                          $(".pwd2").after(data.data);
                      }else{
                          $(".pwd2").nextAll().remove();
                          $(".pwd2").after(data.data);
                      }  
                });
            });
         });
    </script>
    <script type="text/javascript">

    //下面用于多图片上传预览功能

    function setImagePreviews(avalue) {

        var docObj = document.getElementById("doc");

        var dd = document.getElementById("dd");

        dd.innerHTML = "";

        var fileList = docObj.files;

        for (var i = 0; i < fileList.length; i++) {            



            dd.innerHTML += "<div style='float:left' > <img id='img" + i + "'  /> </div>";

            var imgObjPreview = document.getElementById("img"+i); 

            if (docObj.files && docObj.files[i]) {

                //火狐下，直接设img属性

                imgObjPreview.style.display = 'block';

                imgObjPreview.style.width = '150px';

                //imgObjPreview.style.height = '200px';

                //imgObjPreview.src = docObj.files[0].getAsDataURL();

                //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式

                imgObjPreview.src = window.URL.createObjectURL(docObj.files[i]);

            }

            else {

                //IE下，使用滤镜

                docObj.select();

                var imgSrc = document.selection.createRange().text;

                alert(imgSrc)

                var localImagId = document.getElementById("img" + i);

                //必须设置初始大小

                localImagId.style.width = "150px";

                localImagId.style.height = "180px";

                //图片异常的捕捉，防止用户修改后缀来伪造图片

                try {

                    localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";

                    localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;

                }

                catch (e) {

                    alert("您上传的图片格式不正确，请重新选择!");

                    return false;

                }

                imgObjPreview.style.display = 'none';

                document.selection.empty();

            }

        }  

        return true;

    }

	</script>
</block>
